<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@page import="com.webapp.model.Advertisement, com.webapp.model.AdvertisementModel, java.util.List" %>
<% 
	List myAdvertisements =  (List)session.getAttribute("Advertisements");
	System.out.print(myAdvertisements);
	if(myAdvertisements == null)
		response.sendRedirect("Error.jsp");
%>
<!-- include moo talk header file -->
<%@ include file="MooTalkHeader.jsp" %>

		<div id="site_content_text">
			<% 
				String x = request.getParameter("advertisement"); 
				if(x != null) {
					
					if(x.equals("created")) {
						%>
							<p style="color:red;">
								Advertisement Created!
							</p>
						<%
					}
					
					if(x.equals("deleted")) {
						%>
							<p style="color:red;">
								Advertisement was removed!
							</p>
						<%
					}
					
					if(x.equals("disable")) {
						%>
							<p style="color:red;">
								You do not have this function!
							</p>
						<%
					}
					
					if(x.equals("error")) {
						%>
							<p style="color:red;">
								There was an error creating the advertisement!
							</p>
						<%
					}
					
					if(x.equals("no advertisements")) {
						%>
							<p style="color:red;">
								Sorry there are no advertisements!
							</p>
						<%
					}
				} 
			%>
			
			<% if (user.getType().toLowerCase().equals("manager")) { %>
				<h2>All Advertisements</h2>
				<table border="1"> <tr>
										<td><font size="2" face="arial" color="black">Advertisement ID</font></td>
										<td><font size="2" face="arial" color="black">Company</font></td>
										<td><font size="2" face="arial" color="black">Content</font></td>
										<td><font size="2" face="arial" color="black">Date</font></td>
										<td><font size="2" face="arial" color="black">Employee ID</font></td>
										<td><font size="2" face="arial" color="black">Item Name</font></td>
										<td><font size="2" face="arial" color="black">Price</font></td>
										<td><font size="2" face="arial" color="black">Type</font></td>
										<td><font size="2" face="arial" color="black"># of Units</font></td>
				</tr>
				<% if (myAdvertisements.size() == 0) { %>
					<p>There are no advertisements!</p>
					</table>
				<% } else {
					for(int i = 0; i < myAdvertisements.size(); i++) { 
						Advertisement theAdvertisement = (Advertisement)myAdvertisements.get(i);
						if(i%2 == 0) { %>
						<%
						} else { %>
						<% }%>
							<tr>
									<td><font size="2" face="arial" color="black"> <%=theAdvertisement.getAdvertisementId()%> </font></td>
									<td><font size="2" face="arial" color="black">  <%=theAdvertisement.getCompany() %> </font></td>
									<td><font size="2" face="arial" color="black"> <%=theAdvertisement.getContent() %> </font></td>
									<td><font size="2" face="arial" color="black"> <%=theAdvertisement.getDate() %> </font></td>
									<td><font size="2" face="arial" color="black"> <%=theAdvertisement.getEmployeeId() %> </font></td>
									<td><font size="2" face="arial" color="black"> <%=theAdvertisement.getItemName() %> </font></td>
									<td><font size="2" face="arial" color="black"> <%=theAdvertisement.getPrice() %> </font></td>
									<td><font size="2" face="arial" color="black"> <%=theAdvertisement.getType() %> </font></td>
									<td><font size="2" face="arial" color="black"> <%=theAdvertisement.getUnits() %> </font></td>
							</tr>
						
				<% }
				} %> </table>
			<% } else { %>
				<h2>Your advertisements</h2>
			<% } %>
			<br/>
			<hr/>
			<br/>
		</div>
		
<!--  include moo talk footer file -->
<%@ include file="MooTalkFooter.jsp" %>
